import { InjectionKey } from "vue";
import { createStore, useStore as baseUseStore, Store } from "vuex";
import { MenuItem, Breadcrumb } from "../type/meun";
// 为 store state 声明类型
export interface State {
  userMeunList: Array<MenuItem>;
  breadcrumbList: Array<Breadcrumb>;
  keepAlive: Array<string>;
}

// 定义 injection key
export const key: InjectionKey<Store<State>> = Symbol();

export const store = createStore<State>({
  state() {
    return {
      count: 0,
      userMeunList: [],
      breadcrumbList: [],
      keepAlive: [],
    };
  },
  mutations: {
    SET_BREADCRUMN_LIST(state: State, list: Array<Breadcrumb>) {
      state.breadcrumbList = list;
    },
    SET_KEEP_ALIVE(state: State, name: string) {
      state.keepAlive.push(name);
    },
  },
  actions: {},
});

export function useStore() {
  return baseUseStore(key);
}
